#!/usr/bin/python
# -*- coding: UTF-8 -*-
from tkinter.ttk import *
from tkinter import filedialog
from tkinter import *
from scipy.signal import savgol_filter
import pandas as pd
import numpy as np
import threading
import matplotlib.pyplot as plt
size = "550x450"

def smooth(intensity_list):
    j = 1
    while j <= 5:
        intensity_list = savgol_filter(intensity_list, 7, 4)
        j += 1
    return list(intensity_list)

def get_rts(__intensity_list,  __time_list):
    def smooth(intensity_list):
        j = 1
        while j <= 10:
            intensity_list = savgol_filter(intensity_list, 19, 4)
            j += 1
        return list(intensity_list)

    local_maxs = []
    if __intensity_list:
        x = int(len(__intensity_list)*0.2) # 噪音强度是后百分之20的均值
        noise = np.mean(sorted(__intensity_list)[:x])
        __smoothed_intensity_list = smooth(__intensity_list)
        for i in range(1, len(__smoothed_intensity_list)-1):
            if __smoothed_intensity_list[i] > __smoothed_intensity_list[i + 1] and __smoothed_intensity_list[i] >= __smoothed_intensity_list[i - 1] or \
                    __smoothed_intensity_list[i] >= __smoothed_intensity_list[i + 1] and __smoothed_intensity_list[i] > __smoothed_intensity_list[i - 1]:
                if __intensity_list[i] >= 3 * noise: # 三倍信噪比
                    local_maxs.append((__time_list[i], __smoothed_intensity_list[i]))
        local_maxs = sorted(local_maxs, key=lambda _x: _x[1], reverse=True)
        return local_maxs
    return []


class GetIntensity(object):
    def __init__(self, ms_file=None):
        self.ms_file = ms_file
        f = open(ms_file, "r")
        self.content = f.readlines()
        num_list = [idx for idx, i in enumerate(self.content) if i[0] == 'F']
        func_list, rang = [i for i in range(1, len(num_list)+1)], {}
        for idx, i in enumerate(func_list[:-1]):
            rang[i] = (num_list[idx], num_list[idx+1])
        rang[func_list[-1]] = (num_list[-1], len(self.content)+1)
        self.range = rang

    @classmethod
    def split_intensity(cls, lst, total_n, value_index, t_lst):
        length = len(lst) / len(t_lst)
        if int(length) != total_n:
            return None
        intens_lst = []
        i = value_index
        while i <= len(lst) - 1:
            intens_lst.append(lst[i])
            i = i + total_n
        return intens_lst

    def get_profile(self, func, mass1):
        try:
            function, ms_value = func, mass1
            ion_lst = self.content[self.range[function][0]:self.range[function][1]]
            __intensity_list, __time_list = [], []
            for i in ion_lst:
                i = i.strip()
                if len(i) > 1:
                    if i[0] == "R":
                        __time_list.append(float(i.split('\t')[1]))
                    if "." in (i.split('\t')[0]):
                        if float(i.split('\t')[0]) == float(ms_value):
                            __intensity_list.append(float(i.split('\t')[1]))
            return __intensity_list, __time_list
        except KeyError:
            # 如果质谱数据中，例如wash, blank样本中， 没有对应的func和mass1
            return None


    def get_rts(self, __intensity_list,  __time_list):
        def smooth(intensity_list):
            j = 1
            while j <= 10:
                intensity_list = savgol_filter(intensity_list, 19, 4)
                j += 1
            return list(intensity_list)

        local_maxs = []
        if __intensity_list:
            x = int(len(__intensity_list)*0.2) # 噪音强度是后百分之20的均值
            noise = np.mean(sorted(__intensity_list)[:x])
            __smoothed_intensity_list = smooth(__intensity_list)
            for i in range(1, len(__smoothed_intensity_list)-1):
                if __smoothed_intensity_list[i] > __smoothed_intensity_list[i + 1] and __smoothed_intensity_list[i] >= __smoothed_intensity_list[i - 1] or \
                        __smoothed_intensity_list[i] >= __smoothed_intensity_list[i + 1] and __smoothed_intensity_list[i] > __smoothed_intensity_list[i - 1]:
                    if __intensity_list[i] >= 3 * noise: # 三倍信噪比
                        local_maxs.append((__time_list[i], __smoothed_intensity_list[i]))
            local_maxs = sorted(local_maxs, key=lambda _x: _x[1], reverse=True)
            return local_maxs
        return []


    def smooth(self, intensity_list):
        j = 1
        while j <= 10:
            intensity_list = savgol_filter(intensity_list, 19, 4)
            j += 1
        return list(intensity_list)




class GetAllRt(object):
    def __init__(self, compound_list=None, ms_file=None):
        self.com_profile_dict = {}
        self.ms_file = ms_file
        if ".xlsx" in compound_list or '.XLSX' in compound_list:
            data = pd.DataFrame(pd.read_excel(compound_list, usecols=[u'Compound', u'Function', u'Mass', u'RT']))
        if '.csv' in compound_list or '.CSV' in compound_list:
            data = pd.DataFrame(pd.read_csv(compound_list, usecols=[u'Compound', u'Function', u'Mass', u'RT']))
        com, fun, rt = [i for i in data['Compound']], [int(i) for i in data['Function']], [float(i) for i in data['RT']]
        self.com_rt_dict = {i[0]: i[1] for i in zip([i for i in data['Compound']], [i for i in data['RT']])}
        mass1, mass2 = [float(i.split(">")[0].strip()) for i in data['Mass']], \
                       [float(i.split(">")[1].strip()) for i in data['Mass']]
        f_m, f_m_m = list(zip(fun, mass1)), list(zip(fun, mass1, mass2))
        a = GetIntensity(ms_file=self.ms_file)
        self.f_m_profile_dict, self.single_nearest_rt = {}, {}
        for i in f_m:
            f, m = i
            if i not in self.f_m_profile_dict:
                self.f_m_profile_dict[i] = a.get_profile(f, m )

        self.multi_nearest_rt={}
        self.multi_single_rt={}
        self.com_idx = {}
        self.multi, self.single = [], []

        for idx, i in enumerate(f_m):
            f_m1_m2 = f_m_m[idx]
            if f_m_m.count(f_m1_m2) == 1:
                self.single.append(com[idx])
            else:
                self.multi.append(com[idx])
            _a = []
            f, m1, m2 = f_m1_m2
            _a.append(m2)
            for j in f_m_m:
                _f, _m1, _m2 = j
                if f == _f and m1 == _m1 and _m2 not in _a:
                    _a.append(_m2)
            _a = sorted(_a)
            idx1 = _a.index(m2)
            self.com_idx[com[idx]] = (f, m1, len(_a), idx1)

        self.multi_fmm_dict = {}

        for idx, i in enumerate(f_m):
            f_m1_m2 = f_m_m[idx]
            if f_m_m.count(f_m1_m2) > 1:
                compound = com[idx]
                self.multi_fmm_dict[compound] = f_m1_m2

        self.multi_rt_range_dict = {}
        for x in self.multi_fmm_dict:
            ion_parm = self.multi_fmm_dict[x]
            rt_lst = []
            for idx, i in enumerate(f_m_m):
                if ion_parm == i:
                    ren_time = rt[idx]
                    rt_lst.append(ren_time)
            if len(rt_lst) >= 2:
                self.multi_rt_range_dict[x] = (min(rt_lst), max(rt_lst))


        self.com_position = {}
        for i in self.multi:
            idx = com.index(i)
            rt = self.com_rt_dict[i]
            rt_lst = [rt]
            f_m1_m2 = f_m_m[idx]
            for x, y in enumerate(f_m_m):
                if f_m1_m2 == y:
                    rt1 = self.com_rt_dict[com[x]]
                    if rt1 not in rt_lst:
                        rt_lst.append(rt1)
            position = sorted(rt_lst).index(rt)
            func, m1, m2, n = f_m1_m2[0], f_m1_m2[1], f_m1_m2[2], len(rt_lst)
            self.com_position[i] = func, m1, m2, n, position


    def narrow_singe_range(self, intensity_list, time_list, rt, time_range=0.3):
        assert len(intensity_list) == len(time_list)
        narrowed_intensity_list, narrowed_time_list = [], []
        for idx, i in enumerate(time_list):
            if rt - time_range <= i <= rt + time_range:
                narrowed_time_list.append(i)
                narrowed_intensity_list.append(intensity_list[idx])
        return narrowed_intensity_list, narrowed_time_list




    def calculate_single_rt(self):
        b = GetIntensity(ms_file=self.ms_file)
        single_rt_dict = {}
        for i in self.single:
            func, ms, n_value, idx = self.com_idx[i]
            intensity_list, time_list = self.f_m_profile_dict[(func, ms)]
            intensity_list = b.split_intensity(intensity_list, n_value, idx, time_list)
            if intensity_list:
                self.com_profile_dict[i] = intensity_list, time_list
                narrowed_intensity_list, narrowed_time_list = self.narrow_singe_range(intensity_list, time_list, self.com_rt_dict[i], time_range=0.3)
                local_maxs = b.get_rts(narrowed_intensity_list, narrowed_time_list)
                if len(local_maxs) > 0:
                    if len(local_maxs) == 1:
                        single_rt_dict[i] = local_maxs[0][0]
                    if len(local_maxs) > 1:
                        second_largest_time = local_maxs[1][0]
                        second_largest_height = local_maxs[1][1]
                        biggest_height = local_maxs[0][1]
                        biggest_time = local_maxs[0][0]
                        second_rt_diff = abs(self.com_rt_dict[i] - second_largest_time)
                        biggest_rt_diff = abs(self.com_rt_dict[i] - biggest_time)
                        if second_largest_height >= 0.6*biggest_height and biggest_rt_diff - second_rt_diff >= 0.05:
                            single_rt_dict[i] = second_largest_time
                        else:
                            single_rt_dict[i] = biggest_time

                    rt_lst = [x[0] for x in local_maxs]
                    rt = self.com_rt_dict[i]
                    rt_diff_abs_lst = [abs(x - rt) for x in rt_lst]
                    nearest_rt_index = rt_diff_abs_lst.index(min(rt_diff_abs_lst))
                    nearest_rt = rt_lst[nearest_rt_index]
                    self.single_nearest_rt[i] = nearest_rt
        #print (self.single_nearest_rt)
        return single_rt_dict # {物质：time}


    def calculate_multi_rt(self):
        b = GetIntensity(ms_file=self.ms_file)
        multi_rt_dict = {}
        two_rt_mid = {}
        for i in self.multi:
            func, m1, m2, n, position = self.com_position[i]
            for com in self.multi:
                _func, _m1, _m2, _n, _position = self.com_position[com]
                # 如果只有两个物质，需要确定两个物质的rt差异
                if com != i and func == _func and m1 == _m1 and m2 == _m2 and _n == n ==2:
                    rt_diff = self.com_rt_dict[i] - self.com_rt_dict[com]
                    if abs(rt_diff) >= 0.5:
                        rt_mid = (self.com_rt_dict[i] + self.com_rt_dict[com])*0.5
                        if self.com_rt_dict[i] > rt_mid:
                            two_rt_mid[i] = (rt_mid, 'right')
                        if self.com_rt_dict[i] <= rt_mid:
                            two_rt_mid[i] = (rt_mid, 'left')

        for i in self.multi:
            f, m1, total_n, idx = self.com_idx[i]
            __intensity_list, __time_list = self.f_m_profile_dict[(f, m1)]
            __intensity_list = b.split_intensity(__intensity_list, total_n, idx, __time_list)
            if __intensity_list:
                self.com_profile_dict[i] = __intensity_list, __time_list
            all_rt = b.get_rts(__intensity_list, __time_list)

            if all_rt:
                # 如果某个物质是双物质的其中之一，且二者的差异大于0.5，则分别在左右两个区域进行局部最大点的寻找
                if i in two_rt_mid:
                    rt_mid_value, rt_area = two_rt_mid[i]
                    # 如果该物质在右半边，则在右半边区域寻找最大的极值点，截断点是rt均值
                    if rt_area == 'right':
                        rt_right_lst = [x[0] for x in all_rt if x[0] > rt_mid_value]
                        if len(rt_right_lst) > 0:
                            multi_rt_dict[i] = rt_right_lst[0]

                    # 如果该物质在左半边，则在左半边区域寻找最大的极值点
                    if rt_area == 'left':
                        rt_left_lst = [x[0] for x in all_rt if x[0] <= rt_mid_value]
                        if len(rt_left_lst) > 0:
                            multi_rt_dict[i] = rt_left_lst[0]

                else:
                    num, position = self.com_position[i][3], self.com_position[i][4]
                    # 如果峰的总数超过了总物质数量，提取出高度topN的峰
                    if len(all_rt) >= num:
                        # pick top num peak
                        all_rt = [x for x in all_rt if self.multi_rt_range_dict[i][0]-0.3 <= x[0] <= self.multi_rt_range_dict[i][1]+0.3]
                        rt_lst = all_rt[:num]
                        rt_lst = [_[0] for _ in rt_lst]
                        rt_lst = sorted(rt_lst)
                        multi_rt_dict[i] = rt_lst[position]
            else:
                pass
        return multi_rt_dict


class ModifyCsv(object):
    def __init__(self, compound_list=None, std7_ms_file=None, std8_ms_file=None, output=None, pdf_one_file=None):
        self.std7_ms_file, self.std8_ms_file, self.compound_list, self.output = std7_ms_file, std8_ms_file, compound_list, output


        if ".xlsx" in self.compound_list or '.XLSX' in self.compound_list:
            self.data = pd.DataFrame(pd.read_excel(self.compound_list, usecols=[u'Compound', u'RT', u'RTLW', u'RTRW', u'Index', u'IS_correction', u'Index']))
        if ".csv" in self.compound_list or '.CSV' in self.compound_list:
            self.data = pd.DataFrame(pd.read_csv(self.compound_list, usecols=[u'Compound', u'RT', u'RTLW', u'RTRW', u'Index', u'IS_correction', u'Index']))
        self.RTLW = [i for i in self.data['RTLW']]
        self.RTRW = [i for i in self.data['RTRW']]
        self.IS_correction = [''] * len(self.RTLW)
        self.peak_location = ['Nearest' for i in self.RTLW]
        self.com_lst = [i for i in self.data['Compound']]
        self.rt_lst = [0] * len(self.RTLW)
        self.index = [i for i in self.data['Index']]
        self.IS = [self.com_lst[idx] for idx,i in enumerate(self.index) if i[:2] == 'IS']
        self.IS_correction = ['None' if i in self.IS else '' for i in self.com_lst]
        self.pdf_one_file=pdf_one_file
        self.output=output


    def modify(self):
        com_rt_dict = {i[0]: i[1] for i in zip([i for i in self.data['Compound']], [i for i in self.data['RT']])}
        #令x是标曲8，y是标曲7
        x, y = GetAllRt(compound_list=self.compound_list, ms_file=self.std8_ms_file), GetAllRt(compound_list=self.compound_list, ms_file=self.std7_ms_file)



        rt_dict1, rt_dict2, d = x.calculate_single_rt(), y.calculate_single_rt(), {}
        single_nearest_rt_dict1, single_nearest_rt_dict2 = x.single_nearest_rt, y.single_nearest_rt


        f = {}  # f是单物质 0.1 - 0.15
        for i in rt_dict1.keys():
            if i in rt_dict2.keys():
                if 'carnitine' not in i.lower() or i == 'Stearylcarnitine':
                    # 如果标品7和8之间的差异小于0.02，则认为二者rt是一样的
                    if abs(float(rt_dict1[i]) - float(rt_dict2[i])) <= 0.02:
                        if abs(com_rt_dict[i] - (float(rt_dict1[i]) + float(rt_dict2[i])) * 0.5) <= 0.1:
                            d[i] = round((float(rt_dict1[i]) + float(rt_dict2[i]))*0.5, 3)
                        if 0.1 < abs(com_rt_dict[i] - (float(rt_dict1[i]) + float(rt_dict2[i])) * 0.5) <= 0.15:
                            f[i] = round((float(rt_dict1[i]) + float(rt_dict2[i]))*0.5, 3)
                    else:
                        if (abs(float(rt_dict1[i]) - com_rt_dict[i])) > abs((float(rt_dict2[i]) - com_rt_dict[i])):
                            if (abs(float(rt_dict2[i]) - com_rt_dict[i])) <= 0.1:
                                d[i] = float(rt_dict2[i])
                            if 0.1 < (abs(float(rt_dict2[i]) - com_rt_dict[i])) <= 0.15:
                                f[i] = float(rt_dict2[i])

                        if (abs(float(rt_dict1[i]) - com_rt_dict[i])) <= abs((float(rt_dict2[i]) - com_rt_dict[i])):
                            if (abs(float(rt_dict1[i]) - com_rt_dict[i])) <= 0.1:
                                d[i] = float(rt_dict1[i])
                            if 0.1 < (abs(float(rt_dict1[i]) - com_rt_dict[i])) <= 0.15:
                                f[i] = float(rt_dict1[i])
                else:
                    if abs(float(rt_dict1[i]) - float(rt_dict2[i])) <= 0.02:
                        if abs(com_rt_dict[i] - (float(rt_dict1[i]) + float(rt_dict2[i])) * 0.5) <= 0.15:
                            d[i] = round((float(rt_dict1[i]) + float(rt_dict2[i]))*0.5, 3)
                        if 0.15 < abs(com_rt_dict[i] - (float(rt_dict1[i]) + float(rt_dict2[i])) * 0.5) <= 0.3:
                            f[i] = round((float(rt_dict1[i]) + float(rt_dict2[i])) * 0.5, 3)


        for i in x.single:
            if i not in d and i not in f:
                if i in single_nearest_rt_dict1 and i in single_nearest_rt_dict2:
                    if abs(single_nearest_rt_dict1[i] - single_nearest_rt_dict2[i]):
                        rt = 0.5*(single_nearest_rt_dict1[i] + single_nearest_rt_dict2[i])
                        if abs(rt - com_rt_dict[i]) <=0.1:
                            d[i] = round(rt, 3)
                        if 0.1< abs(rt - com_rt_dict[i]) <= 0.15:
                            f[i] = round(rt, 3)

        rt_dict3, rt_dict4 = x.calculate_multi_rt(), y.calculate_multi_rt()
        e = {}  # e多物质0-0.1
        g = {}  # g多物质0.1-0.15
        for i in rt_dict3.keys():
            if i in rt_dict4.keys():
                if 'carnitine' not in i.lower() or i == 'Stearylcarnitine':
                    if abs(float(rt_dict3[i]) - float(rt_dict4[i])) <= 0.02:
                        if abs(com_rt_dict[i] - (float(rt_dict3[i]) + float(rt_dict4[i])) * 0.5) <= 0.1:
                            e[i] = round((float(rt_dict3[i]) + float(rt_dict4[i])) * 0.5, 3)

                        if 0.1 < abs(com_rt_dict[i] - (float(rt_dict3[i]) + float(rt_dict4[i])) * 0.5) <= 0.15:
                            g[i] = round((float(rt_dict3[i]) + float(rt_dict4[i])) * 0.5, 3)

                    else:
                        if (abs(float(rt_dict3[i]) - com_rt_dict[i])) > abs((float(rt_dict4[i]) - com_rt_dict[i])):
                            if (abs(float(rt_dict4[i]) - com_rt_dict[i])) <= 0.1:
                                e[i] = float(rt_dict4[i])
                            if 0.1 < (abs(float(rt_dict4[i]) - com_rt_dict[i])) <= 0.15:
                                g[i] = float(rt_dict4[i])

                        if (abs(float(rt_dict3[i]) - com_rt_dict[i])) <= abs((float(rt_dict4[i]) - com_rt_dict[i])):
                            if (abs(float(rt_dict3[i]) - com_rt_dict[i])) <= 0.1:
                                e[i] = float(rt_dict3[i])
                            if 0.1 < (abs(float(rt_dict3[i]) - com_rt_dict[i])) <= 0.15:
                                g[i] = float(rt_dict3[i])

                else:
                    if abs(float(rt_dict3[i]) - float(rt_dict4[i])) <= 0.02:
                        if abs(com_rt_dict[i] - (float(rt_dict3[i]) + float(rt_dict4[i])) * 0.5) <= 0.15:
                            e[i] = round((float(rt_dict3[i]) + float(rt_dict4[i])) * 0.5, 3)

                        if 0.15 < abs(com_rt_dict[i] - (float(rt_dict3[i]) + float(rt_dict4[i])) * 0.5) <= 0.3:
                            g[i] = round((float(rt_dict3[i]) + float(rt_dict4[i])) * 0.5, 3)


        for i in x.multi:
            if i not in e and i not in g:
                # print (i)
                if i in x.com_profile_dict.keys():
                    x_intensity_list, x_time_list = x.com_profile_dict[i]
                    x_rts = get_rts(x_intensity_list, x_time_list)
                    if x_rts:
                        x_rt_lst = [_[0] for _ in x_rts]
                        rt = x.com_rt_dict[i]
                        rt_diff_abs_lst = [abs(x - rt) for x in x_rt_lst]
                        nearest_rt_index = rt_diff_abs_lst.index(min(rt_diff_abs_lst))
                        nearest_rt = x_rt_lst[nearest_rt_index]
                        x.multi_nearest_rt[i] = nearest_rt

                if i in y.com_profile_dict.keys():
                    y_intensity_list, y_time_list = y.com_profile_dict[i]
                    y_rts = get_rts(y_intensity_list, y_time_list)
                    if y_rts:
                        y_rt_lst = [_[0] for _ in y_rts]
                        rt = y.com_rt_dict[i]
                        rt_diff_abs_lst = [abs(x - rt) for x in y_rt_lst]
                        nearest_rt_index = rt_diff_abs_lst.index(min(rt_diff_abs_lst))
                        nearest_rt = y_rt_lst[nearest_rt_index]
                        y.multi_nearest_rt[i] = nearest_rt

                if i in x.multi_nearest_rt.keys() and i in y.multi_nearest_rt.keys():
                    if abs(x.multi_nearest_rt[i]-y.multi_nearest_rt[i]) <= 0.02:
                        rt_aver = 0.5*(x.multi_nearest_rt[i] + y.multi_nearest_rt[i])
                        if abs(rt_aver - com_rt_dict[i]) <=0.1:
                            e[i] = round(rt_aver, 3)
                        # print (i,0.1)
                        if 0.1< abs(rt_aver - com_rt_dict[i]) <= 0.15:
                            g[i] = round(rt_aver, 3)
                            # print (i,0.15)


        rt_dict = dict(list(d.items()) + list(f.items()) +list(e.items()) + list(g.items()))

        #  print (len(com_full_dict.keys()))
        def draw_all_pdf():
            import os
            from matplotlib.pyplot import MultipleLocator
            if not os.path.exists('PDF'):
                os.makedirs('PDF')
            import PyPDF2
            pdf_lst = []
            for com in self.com_lst:
                if com in x.com_profile_dict.keys():
                    intensity_list, time_list = y.com_profile_dict[com]
                    intensity_list1, time_list1 = x.com_profile_dict[com]
                    intensity_list = smooth(intensity_list)
                    intensity_list1 = smooth(intensity_list1)
                    plt.subplot(2,1,1)
                    plt.plot(time_list, intensity_list)
                    plt.title('upper: std7, below: std8    ' + com)
                    if com in rt_dict:
                        plt.axvline(rt_dict[com], ls="--", color='green', label='Find')
                    plt.axvline(com_rt_dict[com], ls="--", color='red', label='compound list')

                    plt.subplot(2,1,2)
                    plt.plot(time_list1, intensity_list1)
                    if com in rt_dict:
                        plt.axvline(rt_dict[com], ls="--", color='green', label='Find')
                    plt.axvline(com_rt_dict[com], ls="--", color='red', label='compound list')

                    pic_name = 'PDF/' + com + '.pdf'
                    pdf_lst.append(pic_name)
                    plt.savefig(pic_name, dpi=300)
                    plt.clf()

            opened_file = [open(file_name, 'rb') for file_name in pdf_lst]
            pdfFM = PyPDF2.PdfFileMerger()
            for file in opened_file:
                pdfFM.append(file)
            with open(self.pdf_one_file, 'wb') as write_out_file:
                pdfFM.write(write_out_file)
            for file in opened_file:
                file.close()



        draw_all_pdf()
        for idx, i in enumerate(self.com_lst):
            if i in rt_dict.keys():
                rt = rt_dict[i]
            else:
                rt = com_rt_dict[i]
            self.rt_lst[idx] = rt
        output_dataframe = {"Compound":self.com_lst,
                            "RT":self.rt_lst,
                            "RTLW":self.RTLW,
                            "RTRW":self.RTRW,
                            "Peak_location":self.peak_location,
                            "IS_correction":self.IS_correction}
        pd.DataFrame(output_dataframe).to_csv(self.output, index=None)



if __name__ == '__main__':
    A=ModifyCsv(compound_list='compound_list.csv', std7_ms_file='20190809_3_NPH_STD_7.TXT', std8_ms_file='20190809_3_NPH_STD_8.TXT', output='123.csv', pdf_one_file='123.pdf')
    A.modify()



